set(TARGET geo)

# 收集所有源文件
file(GLOB HEADERS CONFIGURE_DEPENDS  "*.h")
file(GLOB SOURCES CONFIGURE_DEPENDS  "*.cpp")
add_library(geo SHARED ${SOURCES} ${HEADERS})
add_library(EasyBrep::Geo ALIAS ${TARGET})
target_compile_definitions(${TARGET} PRIVATE GEO_BUILD_DLL)

# 设置包含目录
target_include_directories(${TARGET} INTERFACE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
    $<INSTALL_INTERFACE:include>
)

# 设置目标属性
target_compile_features(${TARGET} PRIVATE cxx_std_20)

# 设置输出名称
set_target_properties(${TARGET} PROPERTIES
   PUBLIC_HEADER "${HEADERS}"
)

# 创建导出目标
include(CMakePackageConfigHelpers)

# 生成包的版本文件
write_basic_package_version_file(
    "${CMAKE_CURRENT_BINARY_DIR}/GeoConfigVersion.cmake"
    VERSION ${PROJECT_VERSION}
    COMPATIBILITY SameMajorVersion
)

# 设置安装路径变量
set(INCLUDE_INSTALL_DIR include/geo)
set(LIB_INSTALL_DIR lib)

# 配置包配置文件
configure_package_config_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/GeoConfig.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/GeoConfig.cmake"
    INSTALL_DESTINATION lib/cmake/geo
    PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR
)

# 安装配置
install(TARGETS ${TARGET}
    EXPORT GeoTargets
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    PUBLIC_HEADER DESTINATION include/geo
)

# 安装头文件
install(FILES ${HEADERS}
    DESTINATION include/geo
)

# 安装导出文件
install(EXPORT GeoTargets
    FILE GeoTargets.cmake
    NAMESPACE easybreap::
    DESTINATION lib/cmake/geo
)

# 安装包配置文件
install(FILES
    "${CMAKE_CURRENT_BINARY_DIR}/GeoConfig.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/GeoConfigVersion.cmake"
    DESTINATION lib/cmake/geo
)

# 导出目标（用于构建树使用）
export(EXPORT GeoTargets
    FILE "${CMAKE_CURRENT_BINARY_DIR}/GeoTargets.cmake"
    NAMESPACE easybrep::
)
